<template>
  <div v-if="showModal" class="modal">
    <div class="modal-content">
      <div v-if="type == 'del'">
        <img src="@/assets/images/kuang/del.png" alt="" />
        <div class="cancel" @click="closeDialog"></div>
        <div class="confirm" @click="confirm"></div>
      </div>
      <div v-if="type == 'del_res'">
        <img src="@/assets/images/kuang/del_res.png" alt="" />
        <div class="back" @click="closeDialog"></div>
      </div>
      <div v-if="type == 'update'">
        <img src="@/assets/images/kuang/update.png" alt="" />
        <div class="back" @click="closeDialog"></div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
const emit = defineEmits(["confirm", "close"]);

const confirm = () => {
  emit("confirm");
};
defineOptions({
  name: "CustomDialog",
});
const showModal = ref(false);
const type = ref("del_res"); // del 删除确认 del_res 删除结果 update 更新确认
const openDialog = (t) => {
  showModal.value = true;
  type.value = t;
};
const closeDialog = () => {
  showModal.value = false;
  emit("close");
};

defineExpose({
  openDialog,
  closeDialog,
});
</script>

<style scoped lang="scss">
.modal {
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgb(0, 0, 0);
  background-color: rgba(0, 0, 0, 0.4);
}
.modal-content {
  background-color: transparent;
  margin: 15% auto;
  border: 1px solid #888;
  width: 500px;
  position: relative;
  img {
    width: 500px;
  }
}
.cancel,
.confirm,
.back {
  position: absolute;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  cursor: pointer;
}
.cancel {
  right: 25%;
  bottom: 100px;
}
.confirm {
  left: 27%;
  bottom: 100px;
}
.back {
  left: 32%;
  border-radius: 10px;
  height: 50px;
  width: 180px;
  bottom: 100px;
}
</style>
